package Hibernate;

import org.hibernate.HibernateException;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.cfg.AnnotationConfiguration;
import org.omg.PortableServer.Servant;

import Negocio.*;

@SuppressWarnings("unused")
public class HibernateUtil
{
    private static final SessionFactory sessionFactory;
    static
    {
        try
        {
        	AnnotationConfiguration config = new AnnotationConfiguration();
        	// HAY QUE AGREGAR LAS CLASES QUE QUEREMOS QUE PERSISTAN
        	config.addAnnotatedClass(ClienteParticular.class);
        	config.addAnnotatedClass(Empresa.class);
        	config.addAnnotatedClass(Direccion.class);
        	config.addAnnotatedClass(CuentaCorriente.class);
        	config.addAnnotatedClass(Recibo.class);
        	config.addAnnotatedClass(Factura.class);
        	config.addAnnotatedClass(itemFactura.class);
        	config.addAnnotatedClass(Encomienda.class);
        	config.addAnnotatedClass(Paquete.class);
        	config.addAnnotatedClass(ItemEnvio.class);
        	config.addAnnotatedClass(ServicioGranel.class);
        	config.addAnnotatedClass(ServicioBasico.class);
        	config.addAnnotatedClass(ServicioLogistica.class);
        	config.addAnnotatedClass(EmpresaSeguridad.class);
        	config.addAnnotatedClass(EmpresaSeguros.class);
        	config.addAnnotatedClass(AgenteOficial.class);
        	config.addAnnotatedClass(TallerGeneral.class);
        	config.addAnnotatedClass(TallerOficial.class);
        	config.addAnnotatedClass(Carrier.class);
        	config.addAnnotatedClass(PrecioCarrier.class);
        	config.addAnnotatedClass(ProductoLogistica.class);
        	config.addAnnotatedClass(FacturaProveedor.class);
        	config.addAnnotatedClass(Envio.class);
        	config.addAnnotatedClass(EnvioUrgente.class);
        	config.addAnnotatedClass(EnvioInternacional.class);
        	config.addAnnotatedClass(EnvioInterno.class);
        	config.addAnnotatedClass(Remito.class);
        	config.addAnnotatedClass(Vehiculo.class); //Aca esta Sucursal
        	config.addAnnotatedClass(HojaDeRuta.class);
        	config.addAnnotatedClass(Viaje.class);
        	config.addAnnotatedClass(ViajeInterSucursal.class);
        	config.addAnnotatedClass(ViajeOrigenSucursal.class);
        	config.addAnnotatedClass(ViajeSucursalDestino.class);
        	config.addAnnotatedClass(PlanMantenimiento.class); //Aca esta TareaMantenimiento
        	config.addAnnotatedClass(Empleado.class);
        	config.addAnnotatedClass(Sucursal.class);
        	config.addAnnotatedClass(Deposito.class);
        	config.addAnnotatedClass(TareaMantenimiento.class);
        	config.addAnnotatedClass(MantenimientoKilometraje.class);
        	config.addAnnotatedClass(MantenimientoTiempo.class);
        	config.addAnnotatedClass(Usuario.class);
        	sessionFactory = config.buildSessionFactory();
        }
        catch (Throwable ex)
        {
            System.err.println("Initial SessionFactory creation failed." + ex);
            throw new ExceptionInInitializerError(ex);
        }
    }
    
    public static Session getSession()throws HibernateException {
    	return sessionFactory.openSession();
    }
 
    public static SessionFactory getSessionFactory()
    {
        return sessionFactory;
    }
}
